@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        广告面板设置
        <small>列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li class="active">{{ trans('home.panel_ad_setting') }}</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">

        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header">
                    {!! Form::model($adpos,['route'=>['admin.ad.index'],'method'=>'get','name'=>'select_posid'])  !!}
                    <div class="col-xs-2">
                        {!! Form::select('pos_id',$adpos,$id,['class'=>'form-control'])!!}
                    </div>

                    <!-- 选取跳转的js -->
                    <script type="text/javascript">
                        $(".form-control").change(function(){
                            var pan = $(".form-control").val();
                            location.href = "./"+pan;
                        });
                    </script>
                    <!-- 选取跳转的js end-->

                    {!! Form::close()  !!}
                    <div class="pull-right">
                        <a href="{{Route('admin.ad_position.index')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon glyphicon-menu-left"></i> 返回</a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            {!! Form::model($adpos,array('route' => 'admin.ad.sort','class'=>'form-horizontal')) !!}
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">{{ trans('home.panel_ad_list') }}</h3>
                    <div class="box-tools">
                        <a href="{{route('admin.ad.create')}}" type="button" class="btn  btn-success btn-xs"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>
                    </div>

                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">

                    <table class="table table-hover">
                        <tr>
                            <th>排序</th>
                            <th>广告标题</th>
                            <th>广告链接</th>
                            <th style="width: 150px;">操作</th>
                        </tr>
                        @foreach ($ads as $ad)
                            <tr>
                                <td>{!! Form::text('list_order['.$ad->id.']',intval($ad->list_order),['style'=>'width:40px; text-align:center']) !!}</td>
                                <td>{{$ad->title}}</td>
                                <td>{{$ad->url}}</td>

                                <td>
                                    <a href="{{Route('admin.ad.edit',$ad->id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                    <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$ad->id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                                    <div id="modal{{$ad->id}}" class="modal fade">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title">删除警告:</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>确认要删除[{{$ad->title}}]吗?</p>
                                                </div>
                                                <div class="modal-footer">

                                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                    <button itemid="{{$ad->id}}" class="btn  btn-danger01">删除</button>

                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

                                </td>

                            </tr>
                        @endforeach
                    </table>
                    {!! Form::hidden('_method', 'PUT') !!}


                </div>
                <!-- /.box-body -->

                <div class="box-footer">
                    <!-- 分页 -->
                    <div class="pull-right no-margin-pager">
                        {!! $ads->render() !!}
                    </div>

                    {!! Form::hidden('id', $id) !!}
                    <button type="submit" class="btn  btn-success"> 排序</button>

                </div>
                <!-- /.box-footer -->
            </div>
            <!-- /.box -->
            {!! Form::close()  !!}

        </div>
    </div>



</section>
<!-- /.content -->

<script>

        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid");
            //alert("dsaff");
            if(!id) return false;
            $.ajax({
                url:'/admin/ad/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){                    

                    if(result.status){
                        $('#del_alert').modal();
                        $("#ok").hide();
                        $("#no").show();
                        $("#message_content").html(result.info);
                    }else{
                        window.location.reload();
                    }

                }

            });

        });      
        
        
</script>

<script>
    $('.btn-danger').on('click',function(){
        console.log('11');
    });
</script>
@endsection